File: attitude_controller.c

    1   /*
    2    * File: attitude_controller.c
    3    *
    4    * Code generated for Simulink model 'attitude_controller'.
    5    *
    6    * Model version                  : 1.67
    7    * Simulink Coder version         : 8.5 (R2013b) 08-Aug-2013
    8    * C/C++ source code generated on : Mon Feb 03 08:13:29 2014
    9    *
   10    * Target selection: ert.tlc
   11    * Embedded hardware selection: 32-bit Embedded Processor
   12    * Code generation objectives: Unspecified
   13    * Validation result: Not run
   14    */
   15   
   16   #include "attitude_controller.h"
   17   #include "attitude_controller_private.h"
   18   
   19   /* Output and update for referenced model: 'attitude_controller' */
   20   void attitude_controller(const real_T *rtu_Disp_Cmd, const real_T *rtu_Disp_FB,
   21     const real_T *rtu_Rate_FB, const boolean_T *rtu_Engaged, real_T *rty_Surf_Cmd,
   22     rtDW_attitude_controller *localDW, real_T rtp_dispGain, real_T rtp_dispLim,
   23     real_T rtp_rateGain, real_T rtp_rateLim, real_T rtp_intGain, real_T rtp_intLim,
   24     real_T rtp_cmdLim)
   25   {
   26     boolean_T rtb_Notengaged;
   27     real_T rtb_Sum2;
   28     real_T rtb_Sum1;
   29     real_T y;
   30   
   31     /* Logic: '<Root>/Not engaged' */
   32     rtb_Notengaged = !(*rtu_Engaged);
   33   
   34     /* UnitDelay: '<S2>/X' */
   35     rtb_Sum2 = localDW->X_DSTATE;
   36   
   37     /* Switch: '<S2>/Switch' incorporates:
   38      *  Constant: '<S2>/Constant2'
   39      */
   40     if (rtb_Notengaged) {
   41       rtb_Sum2 = 0.0;
   42     }
   43   
   44     /* End of Switch: '<S2>/Switch' */
   45   
   46     /* Saturate: '<S2>/Saturation' */
   47     if (rtb_Sum2 >= rtp_intLim) {
   48       rtb_Sum2 = rtp_intLim;
   49     } else {
   50       if (rtb_Sum2 <= (-rtp_intLim)) {
   51         rtb_Sum2 = -rtp_intLim;
   52       }
   53     }
   54   
   55     /* End of Saturate: '<S2>/Saturation' */
   56   
   57     /* Saturate: '<Root>/Disp Limit' */
   58     if ((*rtu_Disp_Cmd) >= rtp_dispLim) {
   59       y = rtp_dispLim;
   60     } else if ((*rtu_Disp_Cmd) <= (-rtp_dispLim)) {
   61       y = -rtp_dispLim;
   62     } else {
   63       y = *rtu_Disp_Cmd;
   64     }
   65   
   66     /* Gain: '<Root>/Disp Gain' incorporates:
   67      *  Saturate: '<Root>/Disp Limit'
   68      *  Sum: '<Root>/Sum'
   69      */
   70     y = rtp_dispGain * (y - (*rtu_Disp_FB));
   71   
   72     /* Saturate: '<Root>/Rate Limit' */
   73     if (y >= rtp_rateLim) {
   74       y = rtp_rateLim;
   75     } else {
   76       if (y <= (-rtp_rateLim)) {
   77         y = -rtp_rateLim;
   78       }
   79     }
   80   
   81     /* Sum: '<Root>/Sum1' incorporates:
   82      *  Saturate: '<Root>/Rate Limit'
   83      */
   84     rtb_Sum1 = y - (*rtu_Rate_FB);
   85   
   86     /* Sum: '<Root>/Sum2' incorporates:
   87      *  Gain: '<Root>/Rate Gain'
   88      */
   89     y = rtb_Sum2 + (rtp_rateGain * rtb_Sum1);
   90   
   91     /* Saturate: '<Root>/Cmd Limit' */
   92     if (y >= rtp_cmdLim) {
   93       *rty_Surf_Cmd = rtp_cmdLim;
   94     } else if (y <= (-rtp_cmdLim)) {
   95       *rty_Surf_Cmd = -rtp_cmdLim;
   96     } else {
   97       *rty_Surf_Cmd = y;
   98     }
   99   
  100     /* End of Saturate: '<Root>/Cmd Limit' */
  101   
  102     /* Switch: '<S2>/Switch1' */
  103     if (rtb_Notengaged) {
  104       /* Update for UnitDelay: '<S2>/X' incorporates:
  105        *  Constant: '<S2>/Constant2'
  106        */
  107       localDW->X_DSTATE = 0.0;
  108     } else {
  109       /* Update for UnitDelay: '<S2>/X' incorporates:
  110        *  Gain: '<Root>/Int Gain'
  111        *  Product: '<S2>/Product1'
  112        *  Sum: '<S2>/Sum'
  113        */
  114       localDW->X_DSTATE = (attitude_controller_ConstB.Product * (rtp_intGain *
  115         rtb_Sum1)) + rtb_Sum2;
  116     }
  117   
  118     /* End of Switch: '<S2>/Switch1' */
  119   }
  120   
  121   /* Model initialize function */
  122   void attitude_controller_initialize(rtDW_attitude_controller *localDW)
  123   {
  124     /* Registration code */
  125   
  126     /* states (dwork) */
  127     (void) memset((void *)localDW, 0,
  128                   sizeof(rtDW_attitude_controller));
  129   }
  130   
  131   /*
  132    * File trailer for generated code.
  133    *
  134    * [EOF]
  135    */
  136